package com.company.admin.controller.news;

import com.company.admin.common.annotations.VisitAble;
import com.company.admin.common.result.ResultResponse;
import com.company.admin.req.news.CompanyNewsAddRequest;
import com.company.admin.req.news.CompanyNewsDeleteRequest;
import com.company.admin.req.news.CompanyNewsListRequest;
import com.company.admin.req.news.CompanyNewsModifyRequest;
import com.company.admin.resp.news.CompanyNewsListResponse;
import com.company.admin.service.news.CompanyNewsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 赵成林
 * @date 2019/2/17 20:41
 */
@Controller
@RequestMapping(value = "/news")
public class NewsController {

    @Autowired
    private CompanyNewsService companyNewsService;


    @ResponseBody
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public ResultResponse<String> add (@RequestBody CompanyNewsAddRequest request){
        companyNewsService.add(request);
        return ResultResponse.onSuccess("success", null);
    }

    @ResponseBody
    @RequestMapping(value = "/modify", method = RequestMethod.POST)
    public ResultResponse<String> modify(@RequestBody CompanyNewsModifyRequest request){
        companyNewsService.modify(request);
        return ResultResponse.onSuccess("success", null);
    }

    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public ResultResponse<String> delete(@RequestBody CompanyNewsDeleteRequest request){
        companyNewsService.delete(request);
        return ResultResponse.onSuccess("success", null);
    }

    @VisitAble
    @ResponseBody
    @RequestMapping(value = "list", method = RequestMethod.POST)
    public ResultResponse<CompanyNewsListResponse> list(@RequestBody CompanyNewsListRequest request){
        CompanyNewsListResponse response = companyNewsService.list(request);
        return ResultResponse.onSuccess(response, null);
    }
}
